package com.nwcl.basic.service.impl;

import com.nwcl.basic.bo.ResourcesBO;
import com.nwcl.basic.dao.ResourcesDao;
import com.nwcl.basic.entity.Resources;
import com.nwcl.basic.service.ResourcesService;
import com.nwcl.common.utils.BeanUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author liguiqin
 * @date 2023/5/25
 */
@Service
public class ResourcesServiceImpl implements ResourcesService {
    @Autowired
    private ResourcesDao resourcesDao;

    @Override
    public List<ResourcesBO> listByPidTypeAndPids(Integer pidType, List<Integer> pids) {
        List<Resources> list = resourcesDao.listByPidTypeAndPids(pidType,pids);
        if(CollectionUtils.isEmpty(list)){
            return Collections.emptyList();
        }
        return BeanUtil.copyList(list,ResourcesBO.class);
    }

    @Override
    public ResourcesBO getByPidTypeAndPidsFirst(Integer pidType, Integer pid) {
        List<Resources> list = resourcesDao.listByPidTypeAndPidsAndSeq(pidType, Arrays.asList(pid),1);
        if(CollectionUtils.isEmpty(list)){
            return null;
        }
        return BeanUtil.copy(list.get(0),ResourcesBO.class);
    }
}
